{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "Decorator"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "*********I_Am_Decorator_1*******\n",
      "    Hello , I am William.\n",
      "*********I_Am_Decorator_2*******\n"
     ]
    }
   ],
   "source": [
    "def my_decorator(func):\n",
    "    \n",
    "    def wrapper():\n",
    "        print(\"*********I_Am_Decorator_1*******\")\n",
    "        func()\n",
    "        print(\"*********I_Am_Decorator_2*******\")\n",
    "    \n",
    "    return wrapper\n",
    "\n",
    "\n",
    "@my_decorator\n",
    "def print_my_name():\n",
    "    print(\"    Hello , I am William.\")\n",
    "\n",
    "    \n",
    "    \n",
    "    \n",
    "\n",
    "print_my_name()\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "*********I_Am_Decorator_1*******\n",
      "    Hello , I am Tom\n",
      "*********I_Am_Decorator_2*******\n"
     ]
    }
   ],
   "source": [
    "def my_decorator(func):\n",
    "    \n",
    "    def wrapper(*args,**kwargs):\n",
    "        print(\"*********I_Am_Decorator_1*******\")\n",
    "        func(*args,**kwargs)\n",
    "        print(\"*********I_Am_Decorator_2*******\")\n",
    "    \n",
    "    return wrapper\n",
    "\n",
    "\n",
    "@my_decorator\n",
    "def print_my_name(name):\n",
    "    print(\"    Hello , I am \"+name)\n",
    "\n",
    "    \n",
    "    \n",
    "    \n",
    "\n",
    "print_my_name(name=\"Tom\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "*********I_Am_Decorator_1*******\n",
      "    Hello , I am William\n",
      "The message is :Hello\n",
      "*********I_Am_Decorator_2*******\n"
     ]
    }
   ],
   "source": [
    "def my_decorator(msg=\"Not_Hello\"):\n",
    "    def decorated(func):\n",
    "        \n",
    "        def wrapper(*args,**kwargs):\n",
    "            print(\"*********I_Am_Decorator_1*******\")\n",
    "            func(*args,**kwargs)\n",
    "            print(\"The message is :\"+ msg)\n",
    "            print(\"*********I_Am_Decorator_2*******\")\n",
    "    \n",
    "        return wrapper\n",
    "    return decorated\n",
    "\n",
    "\n",
    "@my_decorator(msg=\"Hello\")\n",
    "def print_my_name(name):\n",
    "    print(\"    Hello , I am \"+name)\n",
    "\n",
    "    \n",
    "    \n",
    "    \n",
    "\n",
    "print_my_name(name=\"William\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
